package com.eairlv.share.auto.controller;

import com.eairlv.share.auto.entity.Result;
import com.eairlv.share.auto.entity.bo.ShareTableResultForm;
import com.eairlv.share.auto.entity.bo.TemplateTableForm;
import com.eairlv.share.auto.entity.vo.ShareTableDbInfoVO;
import com.eairlv.share.auto.service.ShareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author eairlv
 * @description
 * @date 14:45 2020/1/13
 */
@Slf4j
@Api(tags = "分片处理接口")
@RestController
@RequestMapping("/share")
public class ShareController {

    @Autowired
    ShareService shareService;

    @ApiOperation("创建模板表")
    @PostMapping("/template")
    public Result createTemplate(@RequestBody TemplateTableForm templateTableForm){
        return shareService.createTemplate(templateTableForm);
    }

    @ApiOperation("获取模板表建表语句")
    @GetMapping("/template/ddl/{tableName}")
    public Result<String> templateTableDDL(@PathVariable String tableName){
        return shareService.templateTableDDL(tableName);
    }

    @ApiOperation("执行分片建表")
    @PutMapping("/execute/{id}")
    public Result execute(@PathVariable Integer id){
        return shareService.execute(id);
    }

    @ApiOperation("查询分片表信息")
    @GetMapping("/info")
    public Result<List<ShareTableDbInfoVO>> info(ShareTableResultForm shareTableResultForm){
        return shareService.info(shareTableResultForm);
    }
}
